<template>
  <el-dialog
    :title="infoId === 0? '修改地址': '查看物流信息'"
    :visible="dialogVisible"
    width="30%"
    @close="handleClose"
  >
    <el-form v-if="infoId === 0" ref="form" :model="form" label-width="80px" :rules="rules">
      <el-form-item label="省市区/县" prop="address">
        <el-cascader
          v-model="form.address"
          :options="cityOptions"
          :value="form.address"
          @change="changeProvince"
        />
      </el-form-item>
      <el-form-item label="详细地址" prop="DetailedAddress">
        <el-input v-model="form.DetailedAddress" />
      </el-form-item>
    </el-form>
    <!-- 自定义 -->
    <el-timeline v-else>
      <el-timeline-item
        v-for="(activity, index) in activities"
        :key="index"
        :icon="index===0?'el-icon-location': ''"
        :type="activity.type"
        :color="index===0?'#0BBD87': ''"
        :size="activity.size"
        :timestamp="activity.ftime"
      >
        {{ activity.context }}
      </el-timeline-item>
    </el-timeline>
    <span slot="footer" class="dialog-footer">
      <el-button @click="$emit('update:dialogVisible',false)">取 消</el-button>
      <el-button type="primary" @click="clickDetailed">确 定</el-button>
    </span>
  </el-dialog>
</template>

<script>
import cityOptions from '@/api/constant/city_data2017_element.js'
import { getLeftKuaidi } from '@/api/orderRun.js'
export default {
  name: 'OrderPopup',
  props: {
    // 判断
    dialogVisible: {
      type: Boolean,
      required: true
    },
    // 判断
    infoId: {
      type: Number,
      required: true
    }
  },
  data() {
    return {
      cityOptions: cityOptions,
      form: {
        address: '',
        DetailedAddress: ''
      },
      // 表单验证
      rules: {
        roleName: [
          { required: true, message: '请选择地址', trigger: 'blur' }
        ],
        roleDesc: [
          { required: true, message: '请输入详细地址', trigger: 'blur' }
        ]
      },
      // 物流数据
      activities: []
    }
  },

  created() {
    this.LeftKuaidi()
  },

  methods: {
    // 练级选择器
    changeProvince(val) {
      console.log(val)
    },
    // 定义退出
    handleClose() {
      this.from = {
        address: '',
        DetailedAddress: ''
      }
      this.$emit('update:dialogVisible', false)
      this.$emit('delId')
    },
    // 确定按钮
    clickDetailed() {
      this.$emit('delId')
      this.$emit('update:dialogVisible', false)
    },
    // 获取数据物流
    async LeftKuaidi() {
      const res = await getLeftKuaidi(this.infoId)
      console.log(res)
      this.activities = res
    }
  }
}
</script>

<style scoped lang='less'>

</style>
